package com.young.springboot.httpclient;

import com.young.commom.httpclient.RequestHeaderInterceptor;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;
import java.util.Map;

/**
 * @description：
 * @author: yangyahui01
 * @date: 11/29/24 2:44 PM
 */
public class MeteorHttpClientRequestHeaderInterceptor extends RequestHeaderInterceptor implements ClientHttpRequestInterceptor {

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        Map<String,String> headers = requestHeaders();
        headers.forEach((key,value) -> {
            request.getHeaders().add(key,value);
        });
        return execution.execute(request, body);
    }

}
